document.getElementById("createSite").onclick=function(){
	window.open ("site2.html?type=POST&", "_blank", "height=700, width=900, top=60, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
	
}
function getList(){
	$.ajax({
		"url":"/site_admin/",
		"error":errorAjax,
		"complete":stop_load_pic,
		"beforeSend":start_load_pic,
		"dataType":"jsonp",
		"success":function(data){
			if(responseCheck(data)){
				for(var i=0;i<data.content.length;i++){
					var tab=document.getElementById("tab")

					var tr=document.createElement("tr")
					var td=document.createElement("td")
					td.textContent=data.content[i].name
					tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].address
					tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].level +"级加油站"
					tr.appendChild(td)

					var td=document.createElement("td")
					td.textContent=data.content[i].bank
					tr.appendChild(td)

					var td=document.createElement("td")
					var b=document.createElement("button")
					var b=document.createElement("button")
					b.setAttribute("siteadmin_id",data.content[i].siteadmin_id)
					b.setAttribute("status",data.content[i].status)
					if (data.content[i].status===true){
						b.textContent="使用中"
						b.className="btn btn-xs btn-success"
						b.onclick=function(){
							var data={}
							data.id=this.getAttribute("siteadmin_id")
							status=this.getAttribute("status")
							if(status==="true"){
								data.status=false
							}
							else{
								data.status=true
							}
							data=JSON.stringify(data)
							if(!confirm("真的要停用吗？")){
								return false;
							}
							$.ajax({
								"url":"/site_admin/",
								"error":errorAjax,
								"beforeSend":start_load_pic,
								"complete":stop_load_pic,
								"data":{"data":data},
								"type":"DELETE",
								"success":function(data){
									if(responseCheck(data)){
										var data=JSON.parse(data)
										alert("操作成功！")
										location.reload()
									}
								}
							})
						}
					}
					else{
						b.textContent="已停用"
						b.className="btn btn-xs btn-danger"
						b.onclick=function(){
							var data={}
							data.id=this.getAttribute("siteadmin_id")
							status=this.getAttribute("status")
							if(status==="true"){
								data.status=false
							}
							else{
								data.status=true
							}
							data=JSON.stringify(data)
							if(!confirm("真的要启用吗？")){
								return false;
							}
							$.ajax({
								"url":"/site_admin/",
								"error":errorAjax,
								"beforeSend":start_load_pic,
								"complete":stop_load_pic,
								"data":{"data":data},
								"type":"DELETE",
								"success":function(data){
									if(responseCheck(data)){
										var data=JSON.parse(data)
										alert("操作成功！")
										location.reload()
									}
								}
							})
						}
					}
					td.appendChild(b)
					tr.appendChild(td)

					var td=document.createElement("td")
					var b=document.createElement("button")
					b.textContent="编辑"
					b.className="btn btn-xs btn-primary"
					b.setAttribute("siteadmin_id",data.content[i].siteadmin_id)
					b.setAttribute("name",data.content[i].name)
					b.setAttribute("img",data.content[i].img)
					b.setAttribute("address",data.content[i].address)
					b.setAttribute("level",data.content[i].level)
					b.setAttribute("bank",data.content[i].bank)
					b.onclick=function(){
						var id=this.getAttribute("siteadmin_id")
						var name=this.getAttribute("name")
						var img=this.getAttribute("img")
						var address=this.getAttribute("address")
						var level=this.getAttribute("level")
						var bank=this.getAttribute("bank")
						
					
						window.open ("site2.html?type=PUT&siteadmin_id="+id+"&name="+name+"&level="+level+"&address="+address+"&img="+img+"&bank="+bank, "_blank", "height=800, width=900, top=160, left=200, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
					}

					td.appendChild(b)
					tr.appendChild(td)

					tab.appendChild(tr)


				}
			}
		}
	})
}
getList()
